import static org.junit.Assert.*;

import org.junit.Test;


public class PlayerTest {

	@Test
	/**
	 * Tests the default constructor for the default constructor of the Player class.
	 */
	public void playerDefaultContructor() {
		Player p_test = new Player ();
		// Not sure how to test this?
	}
	
	@Test
	/**
	 * Test the getShips function for the Player class. Output the names of all the ships.
	 */
	public void getPlayerShips () {
		Player player = new Player();
		assertEquals("Get the ships from a player. Expected output: ", "Aircraft Carrier", player.getShips()[0].getName());
		assertEquals("Get the ships from a player. Expected output: ", "Battleship", player.getShips()[1].getName());
		assertEquals("Get the ships from a player. Expected output: ", "Cruiser", player.getShips()[2].getName());
		assertEquals("Get the ships from a player. Expected output: ", "Submarine", player.getShips()[3].getName());
		assertEquals("Get the ships from a player. Expected output: ", "Destroyer", player.getShips()[4].getName());

	}
	
	@Test
	/**
	 * Test the getShipCells function for Player when the ships have cells assigned to them. 
	 */
	public void getShipCellsValid () {
		Player player = new Player();
		player.getShipCells().add("A1");
		player.getShipCells().add("B1");
		player.getShipCells().add("C1");
		player.getShipCells().add("D1");
		assertEquals("Get all of the cells that the player has placed ships in. Expected output:", "[A1, B1, C1, D1]", player.getShipCells().toString());
	}
	
	@Test
	/**
	 * Test the getShipCells function for Player when no ships have been assigned cells.
	 */
	public void getShipCellsEmpty () {
		Player player = new Player();
		assertEquals("Get all of the cells that ships take up when ships have yet to be placed. Expected output: ", "[]", player.getShipCells().toString());
	}
	
	@Test
	/**
	 * Test the getUsedCell function when the Player has already attacked and cells are in the array. 
	 */
	public void getUsedCellsValid () {
		Player player = new Player();
		player.getUsedCells().add("A1");
		player.getUsedCells().add("B1");
		player.getUsedCells().add("C1");
		player.getUsedCells().add("D1");
		assertEquals("Get all of the cells that the player has attacked when the array is not empty. Expected output:", "[A1, B1, C1, D1]", player.getUsedCells().toString());
	}
	
	@Test
	/**
	 * Test the getUsedCell function when the Player has yet to attack and the array is empty.
	 */
	public void getUsedCellsEmpty () {
		Player player = new Player();
		assertEquals("Get all of the cells that the player has attacked when no cells have been used. Expected output: ", "[]", player.getShipCells().toString());
	}
	
	@Test
	/**
	 * Test the isDefeated function when the player has no ships left on the board and has lost the game.
	 */
	public void playerIsDefeated () {
		Player player = new Player();
		for (int i=1; i<6;i++) {
			String cell = new String("A"+i);
			player.getShips()[0].addCell(cell);
			player.isHit(cell);
		}
		for (int i=1; i<5;i++) {
			String cell = new String("B"+i);
			player.getShips()[1].addCell(cell);
			player.isHit(cell);
		}
		for (int i=1; i<4;i++) {
			String cell = new String("C"+i);
			player.getShips()[2].addCell(cell);
			player.isHit(cell);
		}
		for (int i=1; i<4;i++) {
			String cell = new String("D"+i);
			player.getShips()[3].addCell(cell);
			player.isHit(cell);
		}
		for (int i=1; i<3;i++) {
			String cell = new String("E"+i);
			player.getShips()[4].addCell(cell);
			player.isHit(cell);
		}
		assertEquals("Return the boolean value indicating if the player has been defeated. Expected output: ", true, player.isDefeated());
	}
	
	@Test
	/**
	 * Test the isDefeated function when the player still has shift left on the board is has not lost the game.
	 */
	public void playerIsNotDefeated () {
		Player player = new Player();
		player.getShipCells().add("A1");
		assertEquals("Return the boolean value indicating the player has not been defeated. Expected output: ", "false", player.isDefeated().toString());
	}
	
	@Test
	/**
	 * Test the addAttackedCell method to check if clicked cell is added to the players used cell array.
	 */
	public void addAttackedCellValid() {
		Player player = new Player();
		player.addAttackedCell("A1");
		assertEquals("Add the attacked cell to the players used cell array and display the array. Expected output: ", "[A1]", player.getUsedCells().toString());
	}
	
	@Test
	/**
	 * Test the isValidAttack function to check if a cell that was clicked and was not previously used is valid.
	 */
	public void clickedValidAttackCell () {
		Player player = new Player();
		player.addAttackedCell("A1");
		assertEquals("Return result when clicked cell has not already been used by player. Expected output: ", "true", player.isValidAttack("B1").toString());
	}
	
	@Test
	/**
	 * Test the isValidAttack function to check if a cell that was clicked and was already used is valid.
	 */
	public void clickedInvalidAttackCell () {
		Player player = new Player();
		player.addAttackedCell("A1");
		assertEquals("Return result when clicked cell has not already been used by player. Expected output: ", "false", player.isValidAttack("A1").toString());
	}
	
	@Test
	/**
	 * Test the isHit function to see if an attacked cell is hit if the opposing player has a ship placed at that cell.
	 */
	public void attackIsAHit () {
		Player player = new Player();
		player.getShips()[0].addCell("A1");
		assertEquals("Return result when the attacked cell is in the opposing players ship cells array. Expected output: ", "true", player.isHit("A1").toString());
	}
	
	
	@Test
	/**
	 * Test the isHit function to see if an attacked cell is a hit if the opposing does not have a ship placed in that cell.
	 */
	public void attackIsAMiss () {
		Player player = new Player();
		player.getShips()[0].addCell("A1");
		assertEquals("Return result when the attacked cell is in the opposing players ship cells array. Expected output: ", "false", player.isHit("B1").toString());
	}
}
